/**
 * @FileName: DeviceListAdapter.java
 * @Package:com.bdtop.dbl.ui.adapters
 * @Description: TODO
 * @author: MingjunLi
 * @date:2014-9-29
 * @version V1.0
 */

package com.bdtop.dbl.ui.adapters;

import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bdtop.dbl.R;
import com.bdtop.dbl.model.DeviceInfo;

/**
 * @ClassName: DeviceListAdapter
 * @Description: TODO
 * @author: MingjunLi
 * @date:2014-9-29
 */
public class DeviceListAdapter extends ArrayListAdapter<DeviceInfo> {

    /**
     * @param context
     */
    public DeviceListAdapter(Activity context) {
        super(context);
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        View row = convertView;
        ViewHolder holder;

        if (null == row) {
            row = LayoutInflater.from(mContext).inflate(R.layout.listitem_device, null);

            holder = new ViewHolder();
            holder.deviceIcon = (ImageView) row.findViewById(R.id.device_icon);
            holder.txDeviceName = (TextView) row.findViewById(R.id.device_name);

            row.setTag(holder);
        }
        else {
            holder = (ViewHolder) row.getTag();
        }

        DeviceInfo device = mList.get(position);
        holder.txDeviceName.setText(device.name);

        return row;
    }

    public class ViewHolder {
        public ImageView deviceIcon;
        public TextView txDeviceName;

    }
}
